package controller.day04;

import entity.User;
import service.UserService;
import service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GetByLikeUsernameServlet",value="/GetByLikeUsernameServlet")
public class GetByLikeUsernameServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 获得页面输入的用户名
        String username = request.getParameter("username");

        //2. 调用service
        List<User> userList = userService.getByUsername(username);

        //3. 数据绑定request
        request.setAttribute("userList",userList);

        //3. 页面跳转
        request.getRequestDispatcher("/day04/allUser.jsp").forward(request,response);
    }
}
